#include<bits/stdc++.h>
using namespace std;
int col[12] = {0};
int n, tot = 0;
#define mm(a) memset(a, 0, sizeof(a))

bool check(int c, int r) {
    for (int i = 0; i < r; i++) {
        if (col[i] == c || (abs(col[i] - c) == abs(i - r))) return false;
    }
    return true;
}

void dfs(int r) {
    if (r == n) {tot++; return;}
    for (int c = 0; c < n; c++) {
        if (check(c, r)) {
            col[r] = c;
            dfs(r + 1);
        }
    }
}

int main() {
    int ans[12] = {0};
    for (n = 0; n <= 10; n++) {
        mm(col);
        tot = 0;
        dfs(0);
        ans[n] = tot;
    }
    while (cin >> n) {
        if (n == 0) return 0;
        cout << ans[n] << endl;
    }   
    return 0;
}